package com.hmy.contract.manager.uaa;

import com.hmy.ccp.starter.web.utils.UserContextUtil;
import com.hmy.uaa.api.client.dept.DeptClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * hmy-uaa服务的feign接口统一处理
 *
 * @author songkf
 */
@Slf4j
@Service
public class UaaFeignClientManager {

    @Resource
    private DeptClient deptClient;

    /**
     * 获取当前登录人员所属部门ID集合
     *
     * @return 部门ID集合
     */
    public List<Long> getCurrentUserDeptIds() {
        try {
            return deptClient.getDeptIds(UserContextUtil.getCurrentUserId()).getData();
        } catch (Exception exception) {
            log.error("调用UAA服务的获取当前登录人所属部门信息失败.当前登录人信息是:{}", UserContextUtil.getCurrentUserId(), exception);
        }
        return null;
    }

    public List<Long> getDeptIds(Long userId) {
        try {
            return deptClient.getDeptIds(userId).getData();
        } catch (Exception exception) {
            log.error("调用UAA服务的获取当前登录人所属部门信息失败.当前登录人信息是:{}", UserContextUtil.getCurrentUserId(), exception);
        }
        return null;
    }
}
